package com.zzyy.study.controller;

import com.zzyy.study.entities.Tenant;
import com.zzyy.study.service.TenantService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

//import javax.annotation.Resource;
import java.util.List;

/**
 * @auther zzyy
 * @create 2024-07-05 16:44
 */
@RestController
public class TenantController
{
    @Resource
    private TenantService tenantService;

    /**
     * 创建租户
     * @param tenant
     * @return
     */
    @PostMapping("/tenant/add")
    public Tenant add(@RequestBody Tenant tenant)
    {
        boolean saveOK = tenantService.save(tenant);
        return saveOK ? tenantService.getById(tenant.getTenantId()) : null;
    }

    /*@PostMapping("/tenant/addv2")
    public Tenant addv2(@RequestBody Tenant tenant,
                        @RequestHeader(value = "tenant_id", required = true, defaultValue = "1") String tenant_id)
    {
        System.out.println("********tenant_id: "+tenant_id);
        boolean saveOK = tenantService.save(tenant);
        return saveOK ? tenantService.getById(tenant.getTenantId()) : null;
    }*/

    /**
     * 查询所有租户
     * http://localhost:2477/tenant/list
     * @return
     */
    @GetMapping("/tenant/list")
    public List<Tenant> list()
    {
        return tenantService.list();
    }
}

/**
     ### 2024.7.7 查询租户3所有信息
     GET http://localhost:2477/tenant/list
     Content-Type: application/json
     tenant_id: 2

     ### 2024.7.7 新建租户5
     POST http://localhost:2477/tenant/add
     Content-Type: application/json
     tenant_id: 5

     {
     "tenantName": "关羽",
     "tenantId": "5",
     "email": "gy@163.com"
     }
 */